/*
 * @Descripttion:
 * @Author: Cxy
 * @Date: 2023-02-07 10:16:28
 * @LastEditors: Cxy
 * @LastEditTime: 2023-07-13 09:35:03
 * @FilePath: \giteeBlog\blogAdmin\play\src\utils\comInstall.ts
 */
import type { App, Plugin } from 'vue'
// 类型必须导出否则生成不了.d.ts文件
type SFCWithInstall<T> = T & Plugin

export const comInstall = <T, E extends Record<string, any>>(main: T, extra?: E) => {
  ;(main as SFCWithInstall<T>).install = (app: App) => {
    for (const comp of [main, ...Object.values(extra ?? {})]) {
      app.component(comp.name, comp)
    }
  }
  return main as SFCWithInstall<T> & E
}
